<template>
	<view>
		<button type="default" @click="handleCfy">转录分类</button>
		<button type="default" @click="handleGoods">转录商品</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
			
		// onLoad(){
		// 	console.log(this.$post)
		// },
		methods: {
			handleCfy() {
				uni.request({
					url: 'https://api2105.h5project.cn/1.1/classes/classify',
					method: 'GET',
					header: {
						"X-LC-Id": "7yoqQxyLBNN9MW5rsgTGXbHL-gzGzoHsz",
						"X-LC-Key": "hA8yGYuHjnXWRui1rzTe0C3P",
						"Content-Type": "application/json"
					},
					success: (res) => {
						// console.log(res);
						let {results}=res.data
						let batchObj = {
							"requests": []
						}
						console.log('...',results)
						results.map(item=> {
							delete item.createdAt
							delete item.updatedAt
							console.log(item)
							// console.log('我真的是疯了',item)
							batchObj.requests.push({
								"method": "POST",
								"path": "/1.1/classes/classify",
								"body": item
							})
						})
						console.log('batchObj',batchObj)
						console.log(this.$post)
						this.$post('/1.1/batch', batchObj).then(res=>{
							console.log('...',res)
			})//批量录入分类
					}
				})
			},
			handleGoods() {
				uni.request({
						url: 'https://api2105.h5project.cn/1.1/classes/goods',
						method: 'GET',
						header: {
							"X-LC-Id": "7yoqQxyLBNN9MW5rsgTGXbHL-gzGzoHsz",
							"X-LC-Key": "hA8yGYuHjnXWRui1rzTe0C3P",
							"Content-Type": "application/json"
						},
						success: (res) => {
							// console.log('Bug太多了',res);
							let {
								results
							} = res.data
							let batchObj = {
								"requests": []
							}
							// console.log('...',list)
							results.map(item => {
								delete item.createdAt
								delete item.updatedAt
								console.log('Bug太多了',item)
								batchObj.requests.push({
									"method": "POST",
									"path": "/1.1/classes/goods",
									"body": item
								})
							})
							this.$post('/1.1/batch', batchObj) //批量录入分类
						}
					})
				
			}
		},
	}
</script>

<style>

</style>
